package com.itaem.community.modules.infrastructure.company.department.mapper;

import com.itaem.community.modules.infrastructure.company.department.dto.WorkerBriefDTO;
import com.itaem.community.modules.infrastructure.company.department.dto.WorkerDTO;
import com.itaem.community.modules.infrastructure.company.department.dto.WorkerFireDTO;
import com.itaem.community.modules.infrastructure.company.department.dto.WorkerHireDTO;
import com.itaem.community.modules.infrastructure.company.department.entity.DepartmentEntity;
import com.itaem.community.modules.infrastructure.company.department.entity.WorkerEntity;
import com.itaem.community.modules.infrastructure.user.entity.UserEntity;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;

/**
 * <p>项目名称: community </p>
 * <p>文件名称: WorkerTransformer </p>
 * <p>描述: [类型描述] </p>
 * <p>创建时间: 2020/10/31 </p>
 * <p>作者信息: tomato</p>
 *
 * @author tomato
 * @version v1.0
 */
@Mapper(componentModel = "spring")
public interface WorkerTransformer {

    /**
     * 将新员工的信息提取到数据库实体中
     *
     * @param hireDto 新员工信息
     * @return 数据库实体
     */
    @Mapping(target = "id", ignore = true)
    @Mapping(target = "deleted", expression = "java(Boolean.FALSE)")
    WorkerEntity hireDtoToEntity(WorkerHireDTO hireDto);

    /**
     * 将要解雇的员工信息提取到数据库实体中
     *
     * @param fireDto 要解雇的员工信息
     * @return 数据库实体
     */
    @Mapping(target = "id", ignore = true)
    @Mapping(target = "deleted", ignore = true)
    WorkerEntity fireDtoToEntity(WorkerFireDTO fireDto);

    /**
     * 从员工信息、用户信息、部门信息，组装数据传输对象
     *
     * @param worker         员工信息
     * @param userInfo       用户信息
     * @param departmentInfo 部门信息
     * @return 数据传输传输对象
     */
    @Mapping(target = "departmentName", source = "departmentInfo.departmentName")
    @Mapping(target = "gender", source = "userInfo.gender.gender")
    WorkerDTO toDto(WorkerEntity worker, UserEntity userInfo, DepartmentEntity departmentInfo);
}
